﻿#include "TcpCodec_TurnTable.h"

#include "TurnTableCodec.h"

TcpCodec_TurnTable::TcpCodec_TurnTable()
{
  setObjectName(getClassNameFirstLow<TcpCodec_TurnTable>());
}

TcpCodec_TurnTable::~TcpCodec_TurnTable()
{
}

DataPackage_TcpCodec* TcpCodec_TurnTable::decode(DataPackage_TcpCodec* dataPackageInfo_User)
{
  //4字节deviceID，1字节转台操作类型，12字节操作数据
  QByteArray data=dataPackageInfo_User->getData();
  char* dataPtr=data.data();
  turnTableCodec->sendInstruction(*(uint *)dataPtr,
                                  dataPackageInfo_User->getUserId(),
                                  (TurnTableCodec::TurnTableInstructionFlag)*(uchar*)(dataPtr+4),
                                  *(float*)(dataPtr+5),
                                  *(float*)(dataPtr+9),
                                  *(float*)(dataPtr+13));
  return Q_NULLPTR;
}

TurnTableCodec* TcpCodec_TurnTable::getTurnTableCodec()const
{
  return turnTableCodec;
}

TcpCodec_TurnTable* TcpCodec_TurnTable::setTurnTableCodec(TurnTableCodec*const turnTableCodec)
{
  this->turnTableCodec=turnTableCodec;
  printInjection(this,turnTableCodec);
  return this;
}

void TcpCodec_TurnTable::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setTurnTableCodec(getObjFromMap<TurnTableCodec>(objMap));
}
